import TestFramework as ts_frame
import cb_data
from pyecharts import Line


def close_prem_rank(obj, date, tempCodes):
    srs = obj.DB['Close'].loc[date, tempCodes].rank(ascending=True)
    srs += obj.DB['Convprem'].loc[date, tempCodes].rank(ascending=True)

    t = srs.quantile(0.4)
    return t[t].index


obj = cb_data.CBData()
obj.load_data('Convprem')
strategy = ts_frame.frame_strategy(obj, start='20171231', sel_method=close_prem_rank, round_method=21)
ln = Line()
ln.add('Low price & low premium', strategy.index, strategy['NAV'].values)
ln.render()
